package net.lanelife.casino.caipiao.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Index;
import javax.persistence.Table;

import net.lanelife.casino.caipiao.entity.support.UserRelationEntity;
import net.lanelife.casino.common.entity.annotation.Checked;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

/**
 * 交易明细
 * 
 * @author Lane
 * 
 */
@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "TB_TRANSACTION_DETAIL", indexes = { 
	@Index(name = "IDX_BILLNO", columnList = "BILLNO"),
	@Index(name = "IDX_TRANSACTION_DIRECTION", columnList = "TRANSACTION_DIRECTION"),
	@Index(name = "IDX_TRANSACTION_TYPE", columnList = "TRANSACTION_TYPE"),
	@Index(name = "IDX_TRANSACTION_TIME", columnList = "TRANSACTION_TIME"),
	@Index(name = "IDX_USER_ID", columnList = "USER_ID"),
	@Index(name = "IDX_USER_NAME", columnList = "USER_NAME"),
	@Index(name = "IDX_FLOOR", columnList = "FLOOR"),
	@Index(name = "IDX_PATH", columnList = "PATH"),
	@Index(name = "IDX_PARENT_ID", columnList = "PARENT_ID"),
	@Index(name = "IDX_PARENT_NAME", columnList = "PARENT_NAME")
})
public class TransactionDetail extends UserRelationEntity<Integer> {

	private static final long serialVersionUID = 8952895699116969846L;

	/**
	 * 单号
	 */
	@Checked
	@Column(name = "BILLNO", length = 24, nullable = false)
	private String billNo;

	/**
	 * 交易方向
	 */
	@Checked
	@Enumerated(EnumType.ORDINAL)
	@Column(name = "TRANSACTION_DIRECTION", nullable = false)
	private TransactionDirection transactionDirection;

	/**
	 * 交易类型
	 */
	@Checked
	@Enumerated(EnumType.ORDINAL)
	@Column(name = "TRANSACTION_TYPE", nullable = false)
	private TransactionType transactionType;

	/**
	 * 交易金额
	 */
	@Checked
	@Column(name = "TRANSACTION_AMOUNT", nullable = false)
	private Double transactionAmount;

	/**
	 * 交易时间
	 */
	@Column(name = "TRANSACTION_TIME", nullable = false)
	@Type(type = "net.lanelife.casino.common.entity.usertype.PersistentDateTimeAsMillisLong")
	private DateTime transactionTime;
	/**
	 * 交易前余额
	 */
	@Checked
	@Column(name = "PREVIOUS_BALANCE", nullable = false)
	private Double previousBalance;

	/**
	 * 当前余额
	 */
	@Checked
	@Column(name = "CURRENT_BALANCE", nullable = false)
	private Double currentBalance;

	public static enum TransactionDirection {
		/**
		 * 收入
		 */
		IN,
		/**
		 * 支出
		 */
		OUT
	}

	public static enum TransactionType {
		/**
		 * 账户充值
		 */
		IN_RECHARGE,
		/**
		 * 提款失败返款
		 */
		IN_WITHDRAW_FAIL,
		/**
		 * 转账转入
		 */
		IN_TRANSFER,
		/**
		 * 转账失败返款
		 */
		IN_TRANSFER_FAIL,
		/**
		 * 转账撤销返款
		 */
		IN_TRANSFER_CANCEL,
		/**
		 * 额度调增
		 */
		IN_BALANCE_CHANGE,
		/**
		 * 分红发放
		 */
		IN_DIVIDEND,
		/**
		 * 额度转入
		 */
		IN_BALANCE_EXCHANGE,
		/**
		 * 额度转换失败返款
		 */
		IN_BALANCE_EXCHANGE_FAIL,
		/**
		 * 活动礼金
		 */
		IN_PRIZE,
		/**
		 * 奖金派送
		 */
		IN_BONUS,
		/**
		 * 返点派送
		 */
		IN_REBATE,
		/**
		 * 撤单返款
		 */
		IN_BET_CANCEL,
		/**
		 * 追号解冻
		 */
		IN_CHASE_UNFREEZE,
		
		
		/**
		 * 账户提款
		 */
		OUT_WITHDRAW,
		/**
		 * 转账转出
		 */
		OUT_TRANSFER,
		/**
		 * 转账撤销扣款
		 */
		OUT_TRANSFER_CANCEL,
		/**
		 * 额度调减
		 */
		OUT_BALANCE_CHANGE,
		/**
		 * 分红回收
		 */
		OUT_DIVIDEND,
		/**
		 * 额度转出
		 */
		OUT_BALANCE_EXCHANGE,
		/**
		 * 礼金回收
		 */
		OUT_PRIZE,
		/**
		 * 投注扣款
		 */
		OUT_BET,
		/**
		 * 撤销派奖
		 */
		OUT_BONUS,
		/**
		 * 返点回收
		 */
		OUT_REBATE,
		/**
		 * 追号冻结
		 */
		OUT_CHASE_FREEZE
		
	}
	
	public TransactionDetail() {}
	
	public TransactionDetail(User user) {
		super(user);
	}

	public String getBillNo() {
		return billNo;
	}

	public void setBillNo(String billNo) {
		this.billNo = billNo;
	}

	public TransactionDirection getTransactionDirection() {
		return transactionDirection;
	}

	public void setTransactionDirection(
			TransactionDirection transactionDirection) {
		this.transactionDirection = transactionDirection;
	}

	public TransactionType getTransactionType() {
		return transactionType;
	}

	public void setTransactionType(TransactionType transactionType) {
		this.transactionType = transactionType;
	}

	public Double getTransactionAmount() {
		return transactionAmount;
	}

	public void setTransactionAmount(Double transactionAmount) {
		this.transactionAmount = transactionAmount;
	}

	public DateTime getTransactionTime() {
		return transactionTime;
	}

	public void setTransactionTime(DateTime transactionTime) {
		this.transactionTime = transactionTime;
	}

	public Double getPreviousBalance() {
		return previousBalance;
	}

	public void setPreviousBalance(Double previousBalance) {
		this.previousBalance = previousBalance;
	}

	public Double getCurrentBalance() {
		return currentBalance;
	}

	public void setCurrentBalance(Double currentBalance) {
		this.currentBalance = currentBalance;
	}

}
